package cn.itcast.dao;

import cn.itcast.Member;
import cn.itcast.Orders;
import cn.itcast.Product;
import org.apache.ibatis.annotations.*;


import java.util.List;

public interface OrderDao {

    /**
     * 查询所有订单
     * @return
     */
    @Select("select * from orders")
    @Results(id = "ordersMap",value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "orderNum",column = "orderNum"),
            @Result(property = "orderTime",column = "orderTime"),
            @Result(property = "orderStatus",column = "orderStatus"),
            @Result(property = "peopleCount",column = "peopleCount"),
            @Result(property = "payType",column = "payType"),
            @Result(property = "orderDesc",column = "orderDesc"),
            @Result(property = "product",column = "productId",javaType = Product.class,
            one = @One(select = "cn.itcast.dao.ProductDao.findById"))
    })
    public List<Orders> findAll();

    /**
     * 根据ID查询订单，多表关联查询。
     * @return
     */
    @Select("select * from orders where id = #{id}")
    @Results(id = "orderMap",value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "orderNum",column = "orderNum"),
            @Result(property = "orderTime",column = "orderTime"),
            @Result(property = "orderStatus",column = "orderStatus"),
            @Result(property = "peopleCount",column = "peopleCount"),
            @Result(property = "payType",column = "payType"),
            @Result(property = "orderDesc",column = "orderDesc"),
            @Result(property = "product",column = "productId",javaType = Product.class,
                    one = @One(select = "cn.itcast.dao.ProductDao.findById")),
            @Result(property = "member",column = "memberId",javaType = Member.class,
                    one = @One(select = "cn.itcast.dao.MemberDao.findById")),
            @Result(property = "travellers",column = "id",javaType = java.util.List.class,many = @Many(select = "cn.itcast.dao.TravelleDao.findById"))
    })
    public Orders findById(String id);
}
